package controller;

import dao.DrugDAOImpl;
import model.TDrug;
import utils.DispatcherUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "DisDrugServlet", value = "/disdrug.do")
public class DisDrugServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String s = request.getParameter("drugid");
        int drugid = 0;
        if(s!=null){
            drugid= Integer.parseInt(s);
        }
        DrugDAOImpl drugDAO = new DrugDAOImpl();
            TDrug tDrug = drugDAO.getDrugById(drugid);
            request.setAttribute("tDrug",tDrug);
            DispatcherUtils.openweb("disdrug.jsp",request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
